package com.jiezuo.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiezuo.auth.entity.LoginLog;
import com.jiezuo.auth.mapper.LoginLogMapper;
import com.jiezuo.auth.service.LoginLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
* @description   登陆日志
* @author        庞留杰
* @date          2021/12/01 14:08
* @version       V1.0
**/
@Transactional
@Slf4j
@Service
public class LoginLogServiceImpl extends ServiceImpl<LoginLogMapper, LoginLog> implements LoginLogService{

    @Override
    public IPage<LoginLog> findPage(Page initMpPage, LoginLog loginLog) {
        QueryWrapper<LoginLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete","0");
        queryWrapper.orderByDesc("login_time");
        return this.page(initMpPage,queryWrapper);
    }

    @Override
    public List<LoginLog> findList(LoginLog loginLog) {
        QueryWrapper<LoginLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete","0");
        queryWrapper.orderByDesc("login_time");
        List<LoginLog> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public LoginLog findById(String id) {
        return this.getById(id);
    }

    @Override
    public boolean add(LoginLog loginLog) {
        return this.save(loginLog);
    }

    @Override
    public boolean update(LoginLog loginLog) {
        return this.updateById(loginLog);
    }

    @Override
    public boolean delete(String id) {
        LoginLog loginLog = new LoginLog();
        loginLog.setId(id);
        loginLog.setIs_delete("1");
        return this.updateById(loginLog);
    }
}
